#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import time, sys, datetime, logging
import pandas as pd

import db_utils as util

from app.models.T_DWD_FACT_ZZSC_LZZB_J001 import FeatureInfo, Summary, STSEntry, ExitPdoDataEntry, FactDetail, Range
from app.LoggableObject import LoggableObject


class SummaryJob(LoggableObject):
    """

    """
    config = None

    def __init__(self, p_config=None, ):
        super(SummaryJob, self).__init__()
        self.config = p_config
        pass

    def execute(self):
        self.logger.info('SummaryJob.execute')
        start = datetime.datetime.now()

        self.__do_execute()

        elapsed = float((datetime.datetime.now() - start).seconds)
        self.logger.info("Time Used 4 All ----->>>> %f seconds" % (elapsed))
        pass

    def __do_execute(self):
        """
        """

        db_conn_mpp = util.getConnectionDb2(self.config.DB_HOST_MPP_DB2_BGBDPROD,
                                            self.config.DB_PORT_MPP_DB2_BGBDPROD,
                                            self.config.DB_DBNAME_MPP_DB2_BGBDPROD,
                                            self.config.DB_USER_MPP_DB2_BGBDPROD,
                                            self.config.DB_PASSWORD_MPP_DB2_BGBDPROD)
        self.logger.info('connect db_conn_mpp success?????????????????')

        now = datetime.datetime.now()
        oneday = datetime.timedelta(days=1)
        prev_day = now - oneday
        day = datetime.datetime(year=now.year, month=11, day=7, hour=3, minute=0).strftime('%Y%m%d%H%M%S')

        # FIXME hard code 1st  改成读当前时间的前一天的月份和前一天的date
        day = prev_day.strftime('%Y%m%d')  # '20201223'
        month = prev_day.strftime('%Y%m')  # '202012'
        # NOTE 指标汇总
        self.__execute_zhi_biao_hui_zong(db_conn_mpp=db_conn_mpp,
                                         p_table_name='T_ADS_FACT_LZFH_0001',
                                         p_type='PROD_DATE',
                                         p_value=day,
                                         p_statistics_type='d')
        self.__execute_zhi_biao_hui_zong(db_conn_mpp=db_conn_mpp,
                                         p_table_name='T_ADS_FACT_LZFH_0001',
                                         p_type='PROD_MONTH',
                                         p_value=month,
                                         p_day=day,
                                         p_statistics_type='m')

        # NOTE 机组汇总
        self.__execute_ji_zhu_hui_zong(db_conn_mpp=db_conn_mpp,
                                       p_table_name='T_ADS_FACT_LZFH_0002',
                                       p_type='PROD_DATE',
                                       p_value=day,
                                       p_statistics_type='d')
        self.__execute_ji_zhu_hui_zong(db_conn_mpp=db_conn_mpp,
                                       p_table_name='T_ADS_FACT_LZFH_0002',
                                       p_type='PROD_MONTH',
                                       p_value=month,
                                       p_day=day,
                                       p_statistics_type='m')
        # NOTE 工艺段汇总
        self.__execute_gong_yi_duan_hui_zong(db_conn_mpp=db_conn_mpp,
                                             p_table_name='T_ADS_FACT_LZFH_0003',
                                             p_type='PROD_DATE',
                                             p_value=day,
                                             p_statistics_type='d')
        self.__execute_gong_yi_duan_hui_zong(db_conn_mpp=db_conn_mpp,
                                             p_table_name='T_ADS_FACT_LZFH_0003',
                                             p_type='PROD_MONTH',
                                             p_value=month,
                                             p_day=day,
                                             p_statistics_type='m')

        # close
        util.closeConnection(db_conn_mpp)

    def __execute_zhi_biao_hui_zong(self,
                                    db_conn_mpp=None,
                                    p_table_name=None,
                                    p_type=None,
                                    p_value=None,
                                    p_day=None,
                                    p_statistics_type=None):
        # 按月的加一个限定  prod_date<=‘day'
        c = " and 1=1 "
        if p_day is not None:
            c = " and a.PROD_DATE<='%s' " % (p_day)

        # NOTE
        sql = "select " \
              "a.ITEM_ID, " \
              "a.ITEM_CHN_NAME, " \
              "a.UNIT_CODE, " \
              "a.FACTORY_DESC, " \
              "a.SECTION_ID, " \
              "a.SECTION_NAME, " \
              "sum(a.QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.TOTAL_QTY) as TOTAL_QTY, " \
              "a.PROD_TURN " \
              "from " \
              "(select distinct ENTRY_COILNO,ITEM_ID,ITEM_CHN_NAME,FACTORY_DESC,UNIT_CODE,SECTION_ID,SECTION_NAME,QUALIFIED_QTY,TOTAL_QTY,PROD_DATE,PROD_MONTH,PROD_TURN,REC_CREATE_DATE from BGTAMAL1.T_ADS_FACT_LZZB_0001)as a " \
              "where 1=1 " \
              "and a.%s='%s' " \
              " %s " \
              "group by " \
              "a.ITEM_ID, " \
              "a.ITEM_CHN_NAME, " \
              "a.UNIT_CODE, " \
              "a.FACTORY_DESC, " \
              "a.SECTION_ID, " \
              "a.SECTION_NAME, " \
              "a.PROD_TURN " % (p_type, p_value, c)

        self.logger.info('__execute_zhi_biao_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_zhi_biao_hui_zong(p_row=row,
                                                   p_statistics_type=p_statistics_type,
                                                   p_statistics_time=p_value)
            d['statistics_turn'] = row['prod_turn']
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

        # NOTE
        sql = "select " \
              "a.ITEM_ID, " \
              "a.ITEM_CHN_NAME, " \
              "a.UNIT_CODE, " \
              "a.FACTORY_DESC, " \
              "a.SECTION_ID, " \
              "a.SECTION_NAME, " \
              "sum(a.QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.TOTAL_QTY) as TOTAL_QTY " \
              "from " \
              "(select distinct ENTRY_COILNO,ITEM_ID,ITEM_CHN_NAME,FACTORY_DESC,UNIT_CODE,SECTION_ID,SECTION_NAME,QUALIFIED_QTY,TOTAL_QTY,PROD_DATE,PROD_MONTH,PROD_TURN,REC_CREATE_DATE from BGTAMAL1.T_ADS_FACT_LZZB_0001)as a " \
              "where 1=1 " \
              "and a.%s='%s' " \
              " %s " \
              "group by " \
              "a.ITEM_ID, " \
              "a.ITEM_CHN_NAME, " \
              "a.FACTORY_DESC, " \
              "a.SECTION_ID, " \
              "a.SECTION_NAME, " \
              "a.UNIT_CODE " % (p_type, p_value, c)
        self.logger.info('__execute_zhi_biao_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_zhi_biao_hui_zong(p_row=row,
                                                   p_statistics_type=p_statistics_type,
                                                   p_statistics_time=p_value)
            d['statistics_turn'] = '9'
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

    def __execute_ji_zhu_hui_zong(self,
                                  db_conn_mpp=None,
                                  p_table_name=None,
                                  p_type=None,
                                  p_value=None,
                                  p_day=None,
                                  p_statistics_type=None):
        c = " and a.STATISTICS_TIME='%s' " % (p_value)
        if p_day is not None:
            c = " and a.STATISTICS_TIME<='%s'and a.STATISTICS_TIME>='%s' " % (p_day, p_value)

        # NOTE  FACTORY_DESC,PROD_TURN
        sql = "select " \
              "a.FACTORY_DESC, " \
              "sum(a.NEW_QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.NEW_TOTAL_QTY) as TOTAL_QTY, " \
              "a.PROD_TURN " \
              "from " \
              "(select ITEM_ID,ITEM_CHN_NAME,UNIT_CODE,FACTORY_DESC,SECTION_ID,SECTION_NAME,(case when QUALIFIED_JUDGE=1 then 1 else 0 end) as NEW_QUALIFIED_QTY,1 as NEW_TOTAL_QTY,STATISTICS_TYPE,STATISTICS_TIME,STATISTICS_TURN as PROD_TURN from BGTAMAL1.T_ADS_FACT_LZFH_0001)as a " \
              "where a.STATISTICS_TYPE='d' " \
              "and a.PROD_TURN !='9' " \
              " %s " \
              "group by " \
              "a.FACTORY_DESC, " \
              "a.PROD_TURN" % (c)
        self.logger.info('__execute_ji_zhu_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_ji_zhu_hui_zong(p_row=row,
                                                 p_statistics_type=p_statistics_type,
                                                 p_statistics_time=p_value)
            # 合计
            d['unit_code'] = d['factory_desc']
            d['mark_type'] = d['factory_desc'][-1]
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

        # NOTE FACTORY_DESC
        sql = "select " \
              "a.FACTORY_DESC, " \
              "sum(a.NEW_QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.NEW_TOTAL_QTY) as TOTAL_QTY " \
              "from " \
              "(select ITEM_ID,ITEM_CHN_NAME,UNIT_CODE,FACTORY_DESC,SECTION_ID,SECTION_NAME,(case when QUALIFIED_JUDGE=1 then 1 else 0 end) as NEW_QUALIFIED_QTY,1 as NEW_TOTAL_QTY,STATISTICS_TYPE,STATISTICS_TIME,STATISTICS_TURN as PROD_TURN from BGTAMAL1.T_ADS_FACT_LZFH_0001)as a " \
              "where a.STATISTICS_TYPE='d' " \
              "and a.PROD_TURN !='9' " \
              " %s " \
              "group by " \
              "a.FACTORY_DESC " % (c)
        self.logger.info('__execute_ji_zhu_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_ji_zhu_hui_zong(p_row=row,
                                                 p_statistics_type=p_statistics_type,
                                                 p_statistics_time=p_value)
            d['unit_code'] = d['factory_desc']
            d['mark_type'] = d['factory_desc'][-1]
            d['statistics_turn'] = '9'
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

        # NOTE FACTORY_DESC,UNIT_CODE,PROD_TURN
        sql = "select " \
              "a.FACTORY_DESC, " \
              "a.UNIT_CODE, " \
              "sum(a.NEW_QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.NEW_TOTAL_QTY) as TOTAL_QTY, " \
              "a.PROD_TURN " \
              "from " \
              "(select ITEM_ID,ITEM_CHN_NAME,UNIT_CODE,FACTORY_DESC,SECTION_ID,SECTION_NAME,(case when QUALIFIED_JUDGE=1 then 1 else 0 end) as NEW_QUALIFIED_QTY,1 as NEW_TOTAL_QTY,STATISTICS_TYPE,STATISTICS_TIME,STATISTICS_TURN as PROD_TURN from BGTAMAL1.T_ADS_FACT_LZFH_0001)as a " \
              "where a.STATISTICS_TYPE='d' " \
              "and a.PROD_TURN !='9' " \
              " %s " \
              "group by " \
              "a.FACTORY_DESC, " \
              "a.UNIT_CODE, " \
              "a.PROD_TURN " % (c)
        self.logger.info('__execute_ji_zhu_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_ji_zhu_hui_zong(p_row=row,
                                                 p_statistics_type=p_statistics_type,
                                                 p_statistics_time=p_value)
            d['unit_code'] = row['unit_code']
            d['statistics_turn'] = row['prod_turn']
            # 0:本机组符合率
            # 1：一分厂
            # 2：二分厂
            # 3：三分厂
            # 4：四分厂（现在只做四分厂）
            # 5：精整分厂
            # 如果只算了608/708就写0， 否则写1，2，3，4
            # 如果有真实的unit_code，就是0， 否则就是factory_desc最后一位
            d['mark_type'] = '0'
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

        # NOTE FACTORY_DESC, UNIT_CODE
        sql = "select " \
              "a.FACTORY_DESC, " \
              "sum(a.NEW_QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.NEW_TOTAL_QTY) as TOTAL_QTY, " \
              "a.UNIT_CODE " \
              "from " \
              "(select ITEM_ID,ITEM_CHN_NAME,UNIT_CODE,FACTORY_DESC,SECTION_ID,SECTION_NAME,(case when QUALIFIED_JUDGE=1 then 1 else 0 end) as NEW_QUALIFIED_QTY,1 as NEW_TOTAL_QTY,STATISTICS_TYPE,STATISTICS_TIME,STATISTICS_TURN as PROD_TURN from BGTAMAL1.T_ADS_FACT_LZFH_0001)as a " \
              "where a.STATISTICS_TYPE='d' " \
              "and a.PROD_TURN !='9' " \
              " %s " \
              "group by " \
              "a.FACTORY_DESC, " \
              "a.UNIT_CODE " % (c)
        self.logger.info('__execute_ji_zhu_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_ji_zhu_hui_zong(p_row=row,
                                                 p_statistics_type=p_statistics_type,
                                                 p_statistics_time=p_value)
            d['unit_code'] = row['unit_code']
            # 因为没有prod_trun(即无班维度), 故statistics_turn是合计
            d['statistics_turn'] = '9'
            # 如果有真实的unit_code，就是0， 否则就是factory_desc最后一位
            d['mark_type'] = '0'
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

    def __execute_gong_yi_duan_hui_zong(self,
                                        db_conn_mpp=None,
                                        p_table_name=None,
                                        p_type=None,
                                        p_value=None,
                                        p_day=None,
                                        p_statistics_type=None):
        c = " and a.STATISTICS_TIME='%s' " % (p_value)
        if p_day is not None:
            c = " and a.STATISTICS_TIME<='%s'and a.STATISTICS_TIME>='%s' " % (p_day, p_value)

        # NOTE T_DWD_FACT_ZZSC_LZZB_J001
        sql = "select " \
              "a.SECTION_NAME, " \
              "a.SECTION_ID, " \
              "a.UNIT_CODE, " \
              "sum(a.NEW_QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.NEW_TOTAL_QTY) as TOTAL_QTY, " \
              "a.PROD_TURN " \
              "from " \
              "(select ITEM_ID,ITEM_CHN_NAME,UNIT_CODE,FACTORY_DESC,SECTION_ID,SECTION_NAME,(case when QUALIFIED_JUDGE=1 then 1 else 0 end) as NEW_QUALIFIED_QTY,1 as NEW_TOTAL_QTY,STATISTICS_TYPE,STATISTICS_TIME,STATISTICS_TURN as PROD_TURN from BGTAMAL1.T_ADS_FACT_LZFH_0001)as a " \
              "where a.STATISTICS_TYPE='d' " \
              "and a.PROD_TURN !='9' " \
              " %s " \
              "group by " \
              "a.SECTION_NAME, " \
              "a.SECTION_ID, " \
              "a.UNIT_CODE, " \
              "a.PROD_TURN " % (c)
        self.logger.info('__execute_gong_yi_duan_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_gong_yi_duan_hui_zong(p_row=row,
                                                       p_statistics_type=p_statistics_type,
                                                       p_statistics_time=p_value)
            d['statistics_turn'] = row['prod_turn']

            if d['unit_code'] is None:
                self.logger.err('__execute_gong_yi_duan_hui_zong_err sql=%s' % sql)
                self.logger.err(d)
                self.logger.err(row)
                self.logger.err('????????????????????????????')

            # d['section_id'] = self.__query_section_id(p_db_conn=db_conn_mpp,
            #                                           p_section_name=row['section_name'],
            #                                           p_unit_code=row['unit_code'],
            #                                           d=d)
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

        # NOTE
        sql = "select " \
              "a.SECTION_NAME, " \
              "a.SECTION_ID, " \
              "a.UNIT_CODE, " \
              "sum(a.NEW_QUALIFIED_QTY) as QUALIFIED_QTY, " \
              "sum(a.NEW_TOTAL_QTY) as TOTAL_QTY " \
              "from " \
              "(select ITEM_ID,ITEM_CHN_NAME,UNIT_CODE,FACTORY_DESC,SECTION_ID,SECTION_NAME,(case when QUALIFIED_JUDGE=1 then 1 else 0 end) as NEW_QUALIFIED_QTY,1 as NEW_TOTAL_QTY,STATISTICS_TYPE,STATISTICS_TIME,STATISTICS_TURN as PROD_TURN from BGTAMAL1.T_ADS_FACT_LZFH_0001)as a " \
              "where a.STATISTICS_TYPE='d' " \
              "and a.PROD_TURN !='9' " \
              " %s " \
              "group by " \
              "a.SECTION_NAME, " \
              "a.SECTION_ID, " \
              "a.UNIT_CODE " % (c)
        self.logger.info('__execute_gong_yi_duan_hui_zong sql=%s' % sql)
        try:
            df = util.query(conn=db_conn_mpp, sql=sql)
        except Exception as e:
            self.logger.error(str(e))
        my_list = list()
        for index, row in df.iterrows():
            self.logger.info(row)
            d = self.__row2dic_4_gong_yi_duan_hui_zong(p_row=row,
                                                       p_statistics_type=p_statistics_type,
                                                       p_statistics_time=p_value)
            d['statistics_turn'] = '9'
            # d['section_id'] = self.__query_section_id(p_db_conn=db_conn_mpp, p_section_name=row['section_name'])
            my_list.append(d)
        self.__save2db(p_db_conn=db_conn_mpp, p_table_name=p_table_name, p_list=my_list)

    def __row2dic_4_zhi_biao_hui_zong(self, p_row=None, p_statistics_type=None, p_statistics_time=None):
        d = self.__row2dic_base(p_row=p_row, p_statistics_type=p_statistics_type, p_statistics_time=p_statistics_time)
        d['unit_code'] = p_row['unit_code']
        # ITEM_ID
        # ITEM_CHN_NAME
        d['item_id'] = p_row['item_id']
        d['item_chn_name'] = p_row['item_chn_name']
        d['factory_desc'] = p_row['factory_desc']
        d['section_name'] = p_row['section_name']
        d['section_id'] = p_row['section_id']
        return d

    def __row2dic_4_ji_zhu_hui_zong(self, p_row=None, p_statistics_type=None, p_statistics_time=None):
        d = self.__row2dic_base(p_row=p_row, p_statistics_type=p_statistics_type, p_statistics_time=p_statistics_time)
        # MARK_TYPE	项目属性标记	VARCHAR	8
        # 0:符合率
        # 1：一冷轧分厂
        # 2：二冷轧分厂
        # 3：三冷轧分厂
        # 4：四冷轧分厂
        # 5：五冷轧分厂
        # 进行求和统计
        # # MARK_TYPE hard code 为0
        # d['mark_type'] = '0'
        # # factory_desc 分厂标记 写死成F004
        # d['factory_desc'] = 'F004'

        if p_row.get('factory_desc') is not None:
            d['factory_desc'] = p_row.get('factory_desc')

        return d

    def __row2dic_4_gong_yi_duan_hui_zong(self, p_row=None, p_statistics_type=None, p_statistics_time=None):
        d = self.__row2dic_base(p_row=p_row, p_statistics_type=p_statistics_type, p_statistics_time=p_statistics_time)
        # SECTION_ID
        # SECTION_NAME
        d['unit_code'] = p_row['unit_code']
        d['section_name'] = p_row['section_name']
        d['section_id'] = p_row['section_id']
        return d

    def __row2dic_base(self, p_row=None, p_statistics_type=None, p_statistics_time=None):
        """

        :param p_row:
        :param p_statistics_type:
        :param p_statistics_time:
        :return:
        """
        d = dict()
        d['qualified_qty'] = p_row.get('qualified_qty')
        d['total_qty'] = p_row.get('total_qty')
        summary = Summary(p_cp_num_total=p_row.get('total_qty'), p_num_ok=p_row.get('qualified_qty'))
        d['qualified_rate'] = summary.CP_NUM_OK_RATE
        d['qualified_judge'] = summary.CP_FLAG
        d['statistics_type'] = p_statistics_type
        # 按天统计为8位字符串：yyyymmdd
        # 按月统计为6位字符串：yyyymm
        d['statistics_time'] = p_statistics_time
        # 甲班：1
        # 乙班：2
        # 丙班：3
        # 丁班：4
        # 合计：9
        # statistics_turn
        if p_row.get('prod_turn') is not None:
            d['statistics_turn'] = p_row.get('prod_turn')
        d['rec_creator'] = '--'
        d['rec_create_time'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
        d['rec_revisor'] = '--'
        d['rec_revisor_time'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
        return d

    def __save2db(self, p_db_conn=None, p_table_name=None, p_list=None):
        df = pd.DataFrame(p_list)
        try:
            # NOTE df格式使engine对表的大小写敏感 切切切切切切切切切切切切切切记记记记记记记记记记记记记记记记记记......
            df.to_sql(name=p_table_name.lower(),
                      con=p_db_conn,
                      schema='BGTAMAL1'.lower(),
                      index=False,
                      if_exists='append')
        except Exception as e:
            self.logger.error(str(e))

        self.logger.info('save db done')

    def __query_section_id(self, p_db_conn=None, p_section_name=None, p_unit_code=None, d=None):
        sql = " SELECT DISTINCT SECTION_ID " \
              " FROM BGTAMAL1.T_ADS_FACT_LZZB_J001 " \
              " where 1=1 " \
              " and SECTION_NAME='%s'" % \
              (p_section_name)
        self.logger.info('__query_section_id sql=%s' % sql)
        section_id = None
        try:
            df = util.query(conn=p_db_conn, sql=sql)
            for index, row in df.iterrows():
                section_id = row['section_id']
        except Exception as e:
            self.logger.error(str(e))

        if section_id is None:
            self.logger.info('__query_section_id_no_valid_section_id sql=%s' % sql)
            self.logger.info(d)

        return section_id
